package com.catazzz.springbootstudy.common.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @作者: Tao
 * @日期: 2025/1/7
 * @时间: 10:43
 * @描述: <br><pre>
 */
@Slf4j
@Aspect
@Component
public class AspectOne {

    @Pointcut("execution(public * com.catazzz.springbootstudy.common.aop.*.*(..))")
    public void pointCut() {

    }

    @Before("pointCut()")
    public void before() {
        log.info("before one");
    }

    @After("pointCut()")
    public void after() {
        log.info("after one");
    }

    @AfterReturning("pointCut()")
    public void afterReturning() {
        log.info("afterReturning one");
    }

    @Around("pointCut()")
    public Object around(ProceedingJoinPoint joinPoint) {
        log.info("around one start");
        Object result = null;
        try {
            result = joinPoint.proceed();
        } catch (Throwable e) {
            log.error("around异常", e);
        }
        log.info("around one end");
        return result;
    }
}
